package fms.util;

import java.math.BigDecimal;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 */
public class MathUtil {

    public static float doubleTofloat(double param) {
        BigDecimal b = new BigDecimal(String.valueOf(param));
        float f = b.floatValue();
        System.out.println("doubleTofloat-BigDecimal:" + f);

        String temp = String.valueOf(param);
        return Float.valueOf(temp);
    }

    public static double floatTodouble(float param) {
        BigDecimal b = new BigDecimal(String.valueOf(param));
        double d = b.doubleValue();
        System.out.println("floatTodouble-BigDecimal:" + d);

        String temp = String.valueOf(param);
        return Double.valueOf(temp);
    }

    // 貌似各种方法的效果都一样
    public static void main(String[] arg) {
//        double d = 3.0123456789;
//        System.out.println(d);
//        System.out.println("(float)d:" + (float) d); // double --> float：会丢失精度~~
//        System.out.println("doubleTofloat(d)" + doubleTofloat(d));
//
//
//        float f = (float) 3.0123456789;  // double --> float：会丢失精度~~
//        System.out.println(f);
//        System.out.println("(double)f:" + (double) f); // float -->  扩展精度
//        System.out.println("floatTodouble(f)" + floatTodouble(f));

        BigDecimal statuscount = new BigDecimal(10);
        System.out.println( statuscount.divide(new BigDecimal(150), 2, BigDecimal.ROUND_HALF_UP) );
    }
}
